package repository

import (
	"context"
	"gitee.com/jinmingzhi/cdce-service/internal/model"
	"gitee.com/jinmingzhi/kit/rdb"
)

const (
	areaSchoolField              = "id, rid, course_id, school, area, candidates_num, status, create_time"
	areaSchoolFindAllByRIDAndCID = "select " + areaSchoolField + " from `" + AREASCHOOl + "` where rid =? and course_id = ? and status = ?"
)

type AreaSchool interface{
	FindAllByRIDAndCID(ctx context.Context, rid, course_id uint32) ([]*model.AreaSchool, error)
}

type AreaSchoolImpl struct {
	repo rdb.Repository
}

func NewAreaSchool(repo rdb.Repository) AreaSchool {
	return &AreaSchoolImpl{repo: repo}
}

func (a *AreaSchoolImpl) FindAllByRIDAndCID(ctx context.Context, rid , course_id uint32) ([]*model.AreaSchool, error) {
	data := []*model.AreaSchool{}
	err := a.repo.FindAll(ctx, &data, areaSchoolFindAllByRIDAndCID, rid, course_id, true)
	if err != nil {
		return nil, err
	}
	return data, nil
}

